<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <search ref='search' :config='searchConfig' @search='search' @getHeight='getHeight' />
    <!-- table区域-begin -->
      <vxe-grid
        ref='xGrid'
        v-bind='vexConfig'
        :align='left'
        :border='true'
        :checkbox-config="checkboxConfig"
        :columns='columns'
        :data='dataSource'
        :height='pageHeight-seachHeight-94'
        :loading='loading'
        :resizable='true'
        :showOverflow='true'
        :toolbar-config="tableToolbar"
        size='mini'
        @checkbox-change='selectChangeEvent'
        @checkbox-all="selectChangeEvent"
      >
        <template #toolbar_buttons>
          <div class='table-operator'>
            <a-button type="primary" @click="handleAdd">新增</a-button>
          </div>
        </template>
<!--        <span slot="action" slot-scope="text, record">-->
<!--          <a @click="lickTodetail(record.id,'edit')">编辑</a>-->
<!--          <a-divider type="vertical" />-->
<!--          <a-dropdown>-->
<!--            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>-->
<!--            <a-menu slot="overlay">-->
<!--              <a-menu-item>-->
<!--                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">-->
<!--                  <a>删除</a>-->
<!--                </a-popconfirm>-->
<!--              </a-menu-item>-->
<!--            </a-menu>-->
<!--          </a-dropdown>-->
<!--        </span>-->
        <template  #action='{ row,rowIndex }'>
          <a v-has="'getGoodsAdress:update'" @click='handleEdit(row)'>编辑</a>
          <a-divider type='vertical' />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多
              <a-icon type='down' />
            </a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(row.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
<!--              <a-menu-item v-has="'business:log'">-->
<!--                <a v-has="'business:log'" href='javascript:' @click='handleBusiness("门店管理",row)'>日志</a>-->
<!--              </a-menu-item>-->
            </a-menu>
          </a-dropdown>

        </template>
        <template #pager>
          <vxe-pager
            :currentPage.sync='ipagination.current'
            :layouts="['Total', 'PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump','Sizes', 'FullJump']"
            :page-size.sync='ipagination.pageSize'
            :pageSizes='ipagination.pageSizeOptions'
            :total='ipagination.total'
            @page-change='handlePageChange'>
          </vxe-pager>
        </template>
      </vxe-grid>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <newAdd ref="modalForm" @ok="modalFormOk"></newAdd>

  </a-card>
</template>

<script>
import newAdd from './modules/newAdd'
import JSuperQuery from '@/components/cn-form/JSuperQuery.vue'
import JInput from '@/components/cn-form/JInput.vue'
import { initDictOptions, filterDictText, filterDictTextByCache } from '@/components/dict/CnDictSelectUtil'
import { PageListMixin } from '@/mixins/PageListMixin'
import Vue from 'vue'
import { filterObj } from '@/utils/util'
import JTreeSelect from '@/components/cn-form/JTreeSelect'
import { postAction, getAction } from '../../../api/manage'

//高级查询modal需要参数

export default {
  name: 'canBuyList',
  mixins: [PageListMixin],
  components: {
    JSuperQuery,
    JInput,
    JTreeSelect,
    newAdd,
  },
  data() {
    return {
      description: '可购清单配置',
      //字典数组缓存
      sexDictOptions: [],
      importExcelUrl: `${window._CONFIG['domianURL']}/test/cn-formDemo/importExcel`,
      //表头
      searchConfig: [
        {
          type: 'input',
          name: 'ruleCode',
          placeholder: '请输入可购规则编号'
        },
        {
          type: 'input',
          name: 'ruleName',
          placeholder: '请输入可购规则名称'
        },
        {
          type: 'j-select',
          dictCode:'type',
          name: 'type',
          placeholder: '请选择规则类型'
        },

      ],
      //列设置
      settingColumns: [],
      //列定义  表格改这儿
      columns: [
        {
          width:60,
          fixed: 'left',
          type:'checkbox',
        },
        {
          title: '可购规则名称',
          fixed: 'left',
          minWidth: 120,
          field: 'ruleName',
        },
        {
          title: '可购规则编号',
          minWidth: 120,
          field: 'ruleCode',

          // scopedSlots: {customRender: 'avatar'},
        },
        {
          title: '可购规则类型',
          minWidth: 120,
          field: 'typeStr'
        },
        {
          title: '可购规则维度',
          minWidth: 120,
          field: 'dimensionStr'
        },
        {
          title: '创建人',
          minWidth: 80,
          field: 'createName'
        },
        {
          title: '创建时间',
          minWidth: 80,
          field: 'createTime'
        },
        {
          title: '更新人',
          minWidth: 80,
          field: 'updateName'
        },
        {
          title: '更新时间',
          minWidth: 80,
          field: 'updateTime'
        },
        {
          title: '状态',
          field: 'status',
          fixed: 'right',
          minWidth: 80,
          slots: { default: 'update' }
        },
        {
          title: '操作',
          width: 150,
          minWidth: 80,
          fixed: 'right',
          slots: { default: 'action' }
        }
      ],
      url: {
        list: window._CONFIG['domianDmsURL'] + '/custProduct/findPageList',
        delete: window._CONFIG['domianDmsURL'] + '/custProduct/deleteById',
        detail: window._CONFIG['domianDmsURL'] + '/custProduct/findOneById',
        deleteBatch: '/test/cn-formDemo/deleteBatch',
        exportXlsUrl: '/test/cn-formDemo/exportXls'
      }

    }
  },
  created() {},
  methods: {
    lickTodetail(id, status) {
      getAction(this.url.detail, { id: id }).then(res => {
        this.$refs.modalForm.edit(res.result, status)
      })
    },
    selectCusttype(value) {
      this.$set(this.queryParam, 'custType', value)
    },
    getQueryParams() {
      //高级查询器
      let sqp = {}
      if (this.superQueryParams) {
        sqp['superQueryParams'] = encodeURI(this.superQueryParams)
        sqp['superQueryMatchType'] = this.superQueryMatchType
      }
      var param = Object.assign(sqp, this.queryParam, this.isorter, this.filters)

      param.field = this.getQueryField()
      param.current = this.ipagination.current
      param.size = this.ipagination.pageSize
      delete param.birthdayRange //范围参数不传递后台
      return filterObj(param)
    },
    // initDictConfig() {
    //   console.log("--我才是真的方法!--")
    //初始化字典 - 性别
    // initDictOptions('sex').then((res) => {
    //   if (res.success) {
    //     this.sexDictOptions = res.result;
    //   }
    // });
    // },
    //跳转单据页面
    jump() {
      this.$notification.success('跳转 ： jump')
    },
  },


}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>